package com.ming.mapper;

import com.ming.annotation.AutoFill;
import com.ming.dto.DishPageQueryDTO;
import com.ming.entity.Dish;
import com.ming.vo.DishVO;
import com.ming.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 新增菜品
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 根据ID查询菜品
     */
    @Select("select d.*, c.name as categoryName from dish d left join category c on d.category_id = c.id where d.id = #{id}")
    DishVO getById(Long id);

    /**
     * 动态修改菜品信息
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据ID删除菜品
     */
    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据ID批量删除菜品
     */
    void deleteByIds(List<Long> ids);

    /**
     * 菜品分页查询
     */
    List<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据分类ID查询菜品列表
     */
    List<DishVO> getByCategoryId(Long categoryId);

    /**
     * 根据分类ID统计菜品数量
     */
    @Select("select count(*) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
}